package com.controller;

import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.domain.dto.ManagerLoginReqDTO;
import com.domain.dto.ManagerRegisterRepDTO;
import com.domain.vo.ManagerLoginRespVO;
import com.domain.vo.managerListRespVO;
import com.result.Result;
import com.result.Results;
import com.service.ManagerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class ManagerController {

    @SofaReference(interfaceType = ManagerService.class,  binding = @SofaReferenceBinding(bindingType = "bolt"))
    private ManagerService managerService;

    /**
     * 管理员注册
     * @param requestParam
     * @return
     */
    @PostMapping("/user/register")
    public Result<Void> register(@RequestBody ManagerRegisterRepDTO requestParam){
        log.info("用户注册{}",requestParam.toString());
        managerService.register(requestParam);
        return Results.success();
    }

    /**
     * 管理员登录
     * @param requestParam
     * @return
     */
    @PostMapping("/user/login")
    public Result<ManagerLoginRespVO> login(@RequestBody ManagerLoginReqDTO requestParam){
        log.info("用户登录{}",requestParam.toString());
        ManagerLoginRespVO result = managerService.login(requestParam);
        return Results.success(result);
    }

    /**
     * 查询所有管理员
     * @param
     * @return
     */
    @GetMapping ("/user/list")
    public Result<List<managerListRespVO>> managerList(){
        log.info("查询所有管理员");
        List<managerListRespVO> managerListRespDTOS = managerService.managerList();
        return Results.success(managerListRespDTOS);
    }
}
